package xin.baizhiedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import xin.baizhiedu.entity.*;
import xin.baizhiedu.mapper.*;
import xin.baizhiedu.service.TaskFirstService;
import xin.baizhiedu.service.qgExcelService;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
@Transactional
public class qgExcelServiceImpl implements qgExcelService {


    @Resource
    qgJobNuclearMaterialMapper JobNuclearMaterialMapper;

    @Resource
    qgJobWeekMapper JobWeekMapper;

    @Resource
    qgJobWorkingMapper JobWorkingMapper;

    @Resource
    qgJobWeekMateralMapper qgJobWeekMateralMapper;

    @Resource
    qgJobYcMapper qgJobYcMapper;

    @Resource
    qgJobCheckMapper qgJobCheckMapper;

    @Resource
    qgJobOrderMapper qgJobOrderMapper;

    @Resource
    qgJobOrderWorkingMapper qgJobOrderWorkingMapper;

    @Resource
    qgJobWorkstationMapper qgJobWorkstationMapper;

    @Resource
    qgJobWorkstationTotalMapper qgJobWorkstationTotalMapper;

    @Override
    public List<qgJobNuclearMaterial> qgJobNuclearMaterialList() {
        LambdaQueryWrapper<qgJobNuclearMaterial> wrapper = new LambdaQueryWrapper<>();
        return JobNuclearMaterialMapper.selectList(wrapper);
    }

    @Override
    public List<qgJobNuclearMaterial> qgJobNuclearMaterialListWorking() {
        LambdaQueryWrapper<qgJobNuclearMaterial> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(qgJobNuclearMaterial::getStutStateName,"加工中")
                .gt(qgJobNuclearMaterial::getLastNum, 0);
        return JobNuclearMaterialMapper.selectList(wrapper);
    }

    @Override
    public List<Map<String, Object>> qgJobNuclearMaterialGroupBy() {
        QueryWrapper<qgJobNuclearMaterial> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("sum( PLAN_NUM ) AS NEEDNUM,\n" +
                "\tsum( RECIVE_NUM ) AS RECIVENUM , SUM(LAST_NUM) AS LASTNUM ").groupBy("JOB_CODE");
        return JobNuclearMaterialMapper.selectMaps(queryWrapper);
    }

    @Override
    public List<qgJobWeekMateral> qgJobWeekMateral() {
        LambdaQueryWrapper<qgJobWeekMateral> wrapper = new LambdaQueryWrapper<>();
        return qgJobWeekMateralMapper.selectList(wrapper);
    }

    @Override
    public List<qgJobWeek> qgJobWeekList() {
        LambdaQueryWrapper<qgJobWeek> wrapper = new LambdaQueryWrapper<>();
        return JobWeekMapper.selectList(wrapper);
    }

    @Override
    public qgJobWorking qgJobWorkingOne() {
        LambdaQueryWrapper<qgJobWorking> wrapper = new LambdaQueryWrapper<>();
        return JobWorkingMapper.selectOne(wrapper);
    }

    @Override
    public qgJobYc qgJobYc() {
        LambdaQueryWrapper<qgJobYc> wrapper = new LambdaQueryWrapper<>();
        return qgJobYcMapper.selectOne(wrapper);
    }

    @Override
    public qgJobCheck qgJobCheck() {
        LambdaQueryWrapper<qgJobCheck> wrapper = new LambdaQueryWrapper<>();
        return qgJobCheckMapper.selectOne(wrapper);
    }

    @Override
    public List<qgJobOrder> qgJobOrder() {
        LambdaQueryWrapper<qgJobOrder> wrapper = new LambdaQueryWrapper<>();
        return qgJobOrderMapper.selectList(wrapper);
    }

    @Override
    public List<qgJobOrderWorking> qgJobOrderWorkinglist( String TeamName) {
        LambdaQueryWrapper<qgJobOrderWorking> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(qgJobOrderWorking::getManuType,TeamName);
        return qgJobOrderWorkingMapper.selectList(wrapper);
    }

    @Override
    public List<qgJobOrderWorking> qgJobOrderWorkingOne(String TeamName) {
        QueryWrapper<qgJobOrderWorking> wrapper = new QueryWrapper<>();
        wrapper.select("JOB_CODE");
        wrapper.eq("MANU_TYPE",TeamName);
        wrapper.groupBy("JOB_CODE");
        return qgJobOrderWorkingMapper.selectList(wrapper);
    }

    @Override
    public List<qgJobWorkstation> qgJobWorkstationlist() {
        LambdaQueryWrapper<qgJobWorkstation> wrapper = new LambdaQueryWrapper<>();
        return qgJobWorkstationMapper.selectList(wrapper);
    }

    @Override
    public qgJobWorkstationTotal getqgJobWorkstationTotal() {
        LambdaQueryWrapper<qgJobWorkstationTotal> wrapper = new LambdaQueryWrapper<>();
        return qgJobWorkstationTotalMapper.selectOne(wrapper);
    }


}
